#include "uuid.h"
-static FILE *fd;
-static FILE *ofd;
+static gbfile *fd, *ofd;
#define MYNAME "coastexp"
#define MY_CBUF 4096
void
ce_rd_init(const char *fname)
{
- fd = xfopen(fname, "r", MYNAME);
+ fd = gbfopen(fname, "r", MYNAME);
QUEUE_INIT(&ce_route_head);
QUEUE_INIT(&ce_mark_head);
int len;
char buf[MY_CBUF];
- while ((len = fread(buf, 1, sizeof(buf), fd))) {
- if (!XML_Parse(psr, buf, len, feof(fd))) {
+ while ((len = gbfread(buf, 1, sizeof(buf), fd))) {
+ if (!XML_Parse(psr, buf, len, gbfeof(fd))) {
fatal(MYNAME ":Parse error at %d: %s\n",
(int) XML_GetCurrentLineNumber(psr),
XML_ErrorString(XML_GetErrorCode(psr)));
ce_free_mark(mark);
}
- fclose(fd);
+ gbfclose(fd);
xfree(element);
xfree(cdatastr);
}
uuid_buffer = xcalloc(MY_UBUF,1);
xml_buffer = xcalloc(MY_XBUF, 1);
- ofd = xfopen(fname, "w", MYNAME);
+ ofd = gbfopen(fname, "w", MYNAME);
}
void
ce_wr_deinit(void)
{
- fclose(ofd);
+ gbfclose(ofd);
// Free the buffers used for writing
xfree(time_buffer);
currentMark->id = id;
currentMark->wp = (waypoint *) waypointp;
ENQUEUE_TAIL(&ce_mark_head, ¤tMark->Q);
- fprintf(ofd, "\t\t\t%s\n", id); // CE's departure from XML standard!
+ gbfprintf(ofd, "\t\t\t%s\n", id); // CE's departure from XML standard!
}
/* Generate route trailer XML */
/* GPX - out */
void
-garmin_fs_xml_fprint(FILE *ofd, const waypoint *waypt)
+garmin_fs_xml_fprint(gbfile *ofd, const waypoint *waypt)
{
garmin_fs_t *gmsd = GMSD_FIND(waypt);
if (gmsd == NULL) return;
{
int space = 1;
- fprintf(ofd, "%*s<extensions>\n", space++ * 2, "");
- fprintf(ofd, "%*s<gpxx:WaypointExtension xmlns:gpxx=\"" \
+ gbfprintf(ofd, "%*s<extensions>\n", space++ * 2, "");
+ gbfprintf(ofd, "%*s<gpxx:WaypointExtension xmlns:gpxx=\"" \
"http://www.garmin.com/xmlschemas/GpxExtensions/v2\" " \
"xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" " \
"xsi:schemaLocation=\"http://www.garmin.com/xmlschemas/GpxExtensions/v2 " \
"http://www.garmin.com/xmlschemas/GpxExtensions/v2/GpxExtensionsv2.xsd\">\n", space++ * 2, "");
if (gmsd->flags.proximity)
- fprintf(ofd, "%*s<gpxx:Proximity>%.6f</gpxx:Proximity>\n", space * 2, "", gmsd->proximity);
+ gbfprintf(ofd, "%*s<gpxx:Proximity>%.6f</gpxx:Proximity>\n", space * 2, "", gmsd->proximity);
if (gmsd->flags.temperature)
- fprintf(ofd, "%*s<gpxx:Temperature>%.6f</gpxx:Temperature>\n", space * 2, "", gmsd->temperature);
+ gbfprintf(ofd, "%*s<gpxx:Temperature>%.6f</gpxx:Temperature>\n", space * 2, "", gmsd->temperature);
if (gmsd->flags.depth)
- fprintf(ofd, "%*s<gpxx:Depth>%.6f</gpxx:Depth>\n", space * 2, "", gmsd->depth);
+ gbfprintf(ofd, "%*s<gpxx:Depth>%.6f</gpxx:Depth>\n", space * 2, "", gmsd->depth);
if (gmsd->flags.display)
{
char *cx;
cx = "SymbolAndName";
break;
}
- fprintf(ofd, "%*s<gpxx:DisplayMode>%s</gpxx:DisplayMode>\n", space * 2, "", cx);
+ gbfprintf(ofd, "%*s<gpxx:DisplayMode>%s</gpxx:DisplayMode>\n", space * 2, "", cx);
}
if (gmsd->flags.category && gmsd->category)
{
int i;
gbuint16 cx = gmsd->category;
- fprintf(ofd, "%*s<gpxx:Categories>\n", space++ * 2, "");
+ gbfprintf(ofd, "%*s<gpxx:Categories>\n", space++ * 2, "");
for (i = 0; i < 16; i++)
{
if (cx & 1)
- fprintf(ofd, "%*s<gpxx:Category>Category %d</gpxx:Category>\n", space*2, "", i+1);
+ gbfprintf(ofd, "%*s<gpxx:Category>Category %d</gpxx:Category>\n", space*2, "", i+1);
cx = cx >> 1;
}
- fprintf(ofd, "%*s</gpxx:Categories>\n", --space * 2, "");
+ gbfprintf(ofd, "%*s</gpxx:Categories>\n", --space * 2, "");
}
- fprintf(ofd, "%*s</gpxx:WaypointExtension>\n", --space * 2, "");
- fprintf(ofd, "%*s</extensions>\n", --space * 2, "");
+ gbfprintf(ofd, "%*s</gpxx:WaypointExtension>\n", --space * 2, "");
+ gbfprintf(ofd, "%*s</extensions>\n", --space * 2, "");
}
}
/* for GPX */
void garmin_fs_xml_convert(const int base_tag, int tag, const char *cdatastr, waypoint *waypt);
-void garmin_fs_xml_fprint(FILE *ofd, const waypoint *waypt);
+void garmin_fs_xml_fprint(gbfile *ofd, const waypoint *waypt);
/* common garmin_fs utilities */
#include "defs.h"
#include "xmlgeneric.h"
-static FILE *ofd;
+static gbfile *ofd;
static waypoint *wpt_tmp;
static route_head *trk_head;
static void
glogbook_wr_init(const char *fname)
{
- ofd = xfopen(fname, "w", MYNAME);
+ ofd = gbfopen(fname, "w", MYNAME);
}
static void
glogbook_wr_deinit(void)
{
- fclose(ofd);
+ gbfclose(ofd);
}
static void
glogbook_waypt_pr(const waypoint *wpt)
{
- fprintf(ofd, " <Trackpoint>\n");
- fprintf(ofd, " <Position>\n");
- fprintf(ofd, " <Latitude>%.5f</Latitude>\n", wpt->latitude);
- fprintf(ofd, " <Longitude>%.5f</Longitude>\n", wpt->longitude);
+ gbfprintf(ofd, " <Trackpoint>\n");
+ gbfprintf(ofd, " <Position>\n");
+ gbfprintf(ofd, " <Latitude>%.5f</Latitude>\n", wpt->latitude);
+ gbfprintf(ofd, " <Longitude>%.5f</Longitude>\n", wpt->longitude);
if (wpt->altitude != unknown_alt) {
- fprintf(ofd, " <Altitude>%.3f</Altitude>\n", wpt->altitude);
+ gbfprintf(ofd, " <Altitude>%.3f</Altitude>\n", wpt->altitude);
}
- fprintf(ofd, " </Position>\n");
- fprintf(ofd, " ");
+ gbfprintf(ofd, " </Position>\n");
+ gbfprintf(ofd, " ");
xml_write_time(ofd, wpt->creation_time, "Time");
- fprintf(ofd, " </Trackpoint>\n");
+ gbfprintf(ofd, " </Trackpoint>\n");
}
static void
glogbook_hdr( const route_head *rte)
{
- fprintf(ofd, " <Track>\n");
+ gbfprintf(ofd, " <Track>\n");
}
static void
glogbook_ftr(const route_head *rte)
{
- fprintf(ofd, " </Track>\n");
+ gbfprintf(ofd, " </Track>\n");
}
static void
glogbook_write(void)
{
- fprintf(ofd, "<?xml version=\"1.0\" ?>\n");
- fprintf(ofd, "<History xmlns=\"http://www.garmin.com/xmlschemas/ForerunnerLogbook\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"http://www.garmin.com/xmlschemas/ForerunnerLogbook http://www.garmin.com/xmlschemas/ForerunnerLogbookv1.xsd\" version=\"1\">\n");
- fprintf(ofd, " <Run>\n");
+ gbfprintf(ofd, "<?xml version=\"1.0\" ?>\n");
+ gbfprintf(ofd, "<History xmlns=\"http://www.garmin.com/xmlschemas/ForerunnerLogbook\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"http://www.garmin.com/xmlschemas/ForerunnerLogbook http://www.garmin.com/xmlschemas/ForerunnerLogbookv1.xsd\" version=\"1\">\n");
+ gbfprintf(ofd, " <Run>\n");
track_disp_all(glogbook_hdr, glogbook_ftr, glogbook_waypt_pr);
- fprintf(ofd, " </Run>\n");
- fprintf(ofd, "</History>\n");
+ gbfprintf(ofd, " </Run>\n");
+ gbfprintf(ofd, "</History>\n");
}
void gl_trk_s(const char *args, const char **unused)
static waypoint *wpt_tmp;
static int cache_descr_is_html;
-static FILE *fd;
-static FILE *ofd;
+static gbfile *fd;
+static gbfile *ofd;
static short_handle mkshort_handle;
static const char *input_string = NULL;
return;
}
- fprintf(ofd, "<%s>", tag);
+ gbfprintf(ofd, "<%s>", tag);
QUEUE_FOR_EACH(&ge->queue, elem, tmp) {
gep = BASE_STRUCT(elem, gpx_global_entry, queue);
- fprintf(ofd, "%s", gep->tagdata);
+ gbfprintf(ofd, "%s", gep->tagdata);
/* Some tags we just output once. */
if ((0 == strcmp(tag, "url")) ||
(0 == strcmp(tag, "email"))) {
break;
}
- fprintf(ofd, " ");
+ gbfprintf(ofd, " ");
}
- fprintf(ofd, "</%s>\n", tag);
+ gbfprintf(ofd, "</%s>\n", tag);
}
gpx_rd_init(const char *fname)
{
if ( fname[0] ) {
- fd = xfopen(fname, "r", MYNAME);
+ fd = gbfopen(fname, "r", MYNAME);
}
else {
fd = NULL;
gpx_author = NULL;
}
if (fd) {
- fclose(fd);
+ gbfclose(fd);
}
XML_ParserFree(psr);
psr = NULL;
{
mkshort_handle = mkshort_new_handle();
- ofd = xfopen(fname, "w", MYNAME);
+ ofd = gbfopen(fname, "w", MYNAME);
}
static void
gpx_wr_deinit(void)
{
- fclose(ofd);
+ gbfclose(ofd);
mkshort_del_handle(&mkshort_handle);
}
char *badchar;
char *semi;
int maxentlength = 8;
- len = fread(buf, 1, MY_CBUF_SZ - maxentlength, fd);
- done = feof(fd) || !len;
+ len = gbfread(buf, 1, MY_CBUF_SZ - maxentlength, fd);
+ done = gbfeof(fd) || !len;
buf[len] = '\0';
badchar = buf+len-maxentlength;
badchar = strchr( badchar, '&' );
while ( badchar && len < MY_CBUF_SZ-1) {
semi = strchr( badchar, ';');
while ( extra && !semi ) {
- len += fread( buf+len, 1, 1, fd);
+ len += gbfread( buf+len, 1, 1, fd);
buf[len]='\0';
extra--;
if ( buf[len-1] == ';')
fprint_tag_and_attrs( char *prefix, char *suffix, xml_tag *tag )
{
char **pa;
- fprintf( ofd, "%s%s", prefix, tag->tagname );
+ gbfprintf( ofd, "%s%s", prefix, tag->tagname );
pa = tag->attributes;
if ( pa ) {
while ( *pa ) {
- fprintf( ofd, " %s=\"%s\"", pa[0], pa[1] );
+ gbfprintf( ofd, " %s=\"%s\"", pa[0], pa[1] );
pa += 2;
}
}
- fprintf( ofd, "%s", suffix );
+ gbfprintf( ofd, "%s", suffix );
}
static void
if ( tag->cdata ) {
tmp_ent = xml_entitize( tag->cdata );
- fprintf( ofd, "%s", tmp_ent );
+ gbfprintf( ofd, "%s", tmp_ent );
xfree(tmp_ent);
}
if ( tag->child ) {
xml_write_time( ofd, wpt->gc_data.exported,
"groundspeak:exported" );
}
- fprintf( ofd, "</%s>\n", tag->tagname);
+ gbfprintf( ofd, "</%s>\n", tag->tagname);
}
if ( tag->parentcdata ) {
tmp_ent = xml_entitize(tag->parentcdata);
- fprintf(ofd, "%s", tmp_ent );
+ gbfprintf(ofd, "%s", tmp_ent );
xfree(tmp_ent);
}
tag = tag->sibling;
tmp_ent = xml_entitize(waypointp->url);
if (gpx_wversion_num > 10) {
- fprintf(ofd, " <link href=\"%s%s\">\n",
+ gbfprintf(ofd, " <link href=\"%s%s\">\n",
urlbase ? urlbase : "", tmp_ent);
write_optional_xml_entity(ofd, " ", "text",
waypointp->url_link_text);
- fprintf(ofd, " </link>\n");
+ gbfprintf(ofd, " </link>\n");
} else {
- fprintf(ofd, " <url>%s%s</url>\n",
+ gbfprintf(ofd, " <url>%s%s</url>\n",
urlbase ? urlbase : "", tmp_ent);
write_optional_xml_entity(ofd, " ", "urlname",
waypointp->url_link_text);
break;
}
if (fix) {
- fprintf(ofd, "%s<fix>%s</fix>\n", indent, fix);
+ gbfprintf(ofd, "%s<fix>%s</fix>\n", indent, fix);
}
if (waypointp->sat > 0) {
- fprintf(ofd, "%s<sat>%d</sat>\n", indent, waypointp->sat);
+ gbfprintf(ofd, "%s<sat>%d</sat>\n", indent, waypointp->sat);
}
if (waypointp->hdop) {
- fprintf(ofd, "%s<hdop>%f</hdop>\n", indent, waypointp->hdop);
+ gbfprintf(ofd, "%s<hdop>%f</hdop>\n", indent, waypointp->hdop);
}
if (waypointp->vdop) {
- fprintf(ofd, "%s<vdop>%f</vdop>\n", indent, waypointp->vdop);
+ gbfprintf(ofd, "%s<vdop>%f</vdop>\n", indent, waypointp->vdop);
}
if (waypointp->pdop) {
- fprintf(ofd, "%s<pdop>%f</pdop>\n", indent, waypointp->pdop);
+ gbfprintf(ofd, "%s<pdop>%f</pdop>\n", indent, waypointp->pdop);
}
}
gpx_write_common_position(const waypoint *waypointp, const char *indent)
{
if (waypointp->altitude != unknown_alt) {
- fprintf(ofd, "%s<ele>%f</ele>\n",
+ gbfprintf(ofd, "%s<ele>%f</ele>\n",
indent, waypointp->altitude);
}
if (waypointp->creation_time) {
mkshort(mkshort_handle, odesc) :
waypointp->shortname;
- fprintf(ofd, "<wpt lat=\"" FLT_FMT "\" lon=\"" FLT_FMT "\">\n",
+ gbfprintf(ofd, "<wpt lat=\"" FLT_FMT "\" lon=\"" FLT_FMT "\">\n",
waypointp->latitude,
waypointp->longitude);
if (gpx_wversion_num > 10) {
garmin_fs_xml_fprint(ofd, waypointp);
}
- fprintf(ofd, "</wpt>\n");
+ gbfprintf(ofd, "</wpt>\n");
}
static void
{
fs_xml *fs_gpx;
- fprintf(ofd, "<trk>\n");
+ gbfprintf(ofd, "<trk>\n");
write_optional_xml_entity(ofd, " ", "name", rte->rte_name);
write_optional_xml_entity(ofd, " ", "desc", rte->rte_desc);
if (rte->rte_num) {
- fprintf(ofd, "<number>%d</number>\n", rte->rte_num);
+ gbfprintf(ofd, "<number>%d</number>\n", rte->rte_num);
}
- fprintf(ofd, "<trkseg>\n");
+ gbfprintf(ofd, "<trkseg>\n");
fs_gpx = (fs_xml *)fs_chain_find( rte->fs, FS_GPX );
if ( fs_gpx ) {
{
fs_xml *fs_gpx;
- fprintf(ofd, "<trkpt lat=\"" FLT_FMT_T "\" lon=\"" FLT_FMT_T "\">\n",
+ gbfprintf(ofd, "<trkpt lat=\"" FLT_FMT_T "\" lon=\"" FLT_FMT_T "\">\n",
waypointp->latitude,
waypointp->longitude);
/* These were accidentally removed from 1.1 */
if (gpx_wversion_num == 10) {
if (waypointp->course >= 0) {
- fprintf(ofd, " <course>%f</course>\n",
+ gbfprintf(ofd, " <course>%f</course>\n",
waypointp->course);
}
if (waypointp->speed >= 0) {
- fprintf(ofd, " <speed>%f</speed>\n",
+ gbfprintf(ofd, " <speed>%f</speed>\n",
waypointp->speed);
}
}
fprint_xml_chain( fs_gpx->tag, waypointp );
}
- fprintf(ofd, "</trkpt>\n");
+ gbfprintf(ofd, "</trkpt>\n");
}
static void
gpx_track_tlr(const route_head *rte)
{
- fprintf(ofd, "</trkseg>\n");
- fprintf(ofd, "</trk>\n");
+ gbfprintf(ofd, "</trkseg>\n");
+ gbfprintf(ofd, "</trk>\n");
}
static
{
fs_xml *fs_gpx;
- fprintf(ofd, "<rte>\n");
+ gbfprintf(ofd, "<rte>\n");
write_optional_xml_entity(ofd, " ", "name", rte->rte_name);
write_optional_xml_entity(ofd, " ", "desc", rte->rte_desc);
if (rte->rte_num) {
- fprintf(ofd, " <number>%d</number>\n", rte->rte_num);
+ gbfprintf(ofd, " <number>%d</number>\n", rte->rte_num);
}
fs_gpx = (fs_xml *)fs_chain_find( rte->fs, FS_GPX );
{
fs_xml *fs_gpx;
- fprintf(ofd, " <rtept lat=\"" FLT_FMT_R "\" lon=\"" FLT_FMT_R "\">\n",
+ gbfprintf(ofd, " <rtept lat=\"" FLT_FMT_R "\" lon=\"" FLT_FMT_R "\">\n",
waypointp->latitude,
waypointp->longitude);
fprint_xml_chain( fs_gpx->tag, waypointp );
}
- fprintf(ofd, " </rtept>\n");
+ gbfprintf(ofd, " </rtept>\n");
}
static void
gpx_route_tlr(const route_head *rte)
{
- fprintf(ofd, "</rte>\n");
+ gbfprintf(ofd, "</rte>\n");
}
static
track_disp_all(NULL, NULL, gpx_waypt_bound_calc);
if (waypt_bounds_valid(&all_bounds)) {
- fprintf(ofd, "<bounds minlat=\"%0.9f\" minlon=\"%0.9f\" "
+ gbfprintf(ofd, "<bounds minlat=\"%0.9f\" minlon=\"%0.9f\" "
"maxlat=\"%0.9f\" maxlon=\"%0.9f\"/>\n",
all_bounds.min_lat, all_bounds.min_lon,
all_bounds.max_lat, all_bounds.max_lon);
setshort_length(mkshort_handle, short_length);
- fprintf(ofd, "<?xml version=\"1.0\" encoding=\"%s\"?>\n", global_opts.charset_name);
- fprintf(ofd, "<gpx\n version=\"%s\"\n", gpx_wversion);
- fprintf(ofd, "creator=\"" CREATOR_NAME_URL "\"\n");
- fprintf(ofd, "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n");
- fprintf(ofd, "xmlns=\"http://www.topografix.com/GPX/%c/%c\"\n", gpx_wversion[0], gpx_wversion[2]);
+ gbfprintf(ofd, "<?xml version=\"1.0\" encoding=\"%s\"?>\n", global_opts.charset_name);
+ gbfprintf(ofd, "<gpx\n version=\"%s\"\n", gpx_wversion);
+ gbfprintf(ofd, "creator=\"" CREATOR_NAME_URL "\"\n");
+ gbfprintf(ofd, "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n");
+ gbfprintf(ofd, "xmlns=\"http://www.topografix.com/GPX/%c/%c\"\n", gpx_wversion[0], gpx_wversion[2]);
if (xsi_schema_loc) {
- fprintf(ofd, "xsi:schemaLocation=\"%s\">\n", xsi_schema_loc);
+ gbfprintf(ofd, "xsi:schemaLocation=\"%s\">\n", xsi_schema_loc);
} else {
- fprintf(ofd,
+ gbfprintf(ofd,
"xsi:schemaLocation=" DEFAULT_XSI_SCHEMA_LOC_FMT">\n",
gpx_wversion[0], gpx_wversion[2],
gpx_wversion[0], gpx_wversion[2]);
}
if (gpx_wversion_num > 10) {
- fprintf(ofd, "<metadata>\n");
+ gbfprintf(ofd, "<metadata>\n");
}
gpx_write_gdata(&gpx_global->name, "name");
gpx_write_gdata(&gpx_global->desc, "desc");
gpx_write_bounds();
if (gpx_wversion_num > 10) {
- fprintf(ofd, "</metadata>\n");
+ gbfprintf(ofd, "</metadata>\n");
}
waypt_disp_all(gpx_waypt_pr);
gpx_route_pr();
gpx_track_pr();
- fprintf(ofd, "</gpx>\n");
+ gbfprintf(ofd, "</gpx>\n");
}
#include "defs.h"
#include "xmlgeneric.h"
-static FILE *ofd;
+static gbfile *ofd;
static waypoint *wpt_tmp;
static route_head *trk_head;
static void
hiketech_wr_init(const char *fname)
{
- ofd = xfopen(fname, "w", MYNAME);
+ ofd = gbfopen(fname, "w", MYNAME);
}
static void
hiketech_wr_deinit(void)
{
- fclose(ofd);
+ gbfclose(ofd);
}
static void
hiketech_trk_hdr(const route_head *rte)
{
- fprintf(ofd, "<trk>\n");
+ gbfprintf(ofd, "<trk>\n");
write_optional_xml_entity(ofd, " ", "ident", rte->rte_name);
}
static void
hiketech_trk_tlr(const route_head *rte)
{
- fprintf(ofd, "</trk>\n");
+ gbfprintf(ofd, "</trk>\n");
}
static void
{
char tbuf[80];
strftime(tbuf, sizeof(tbuf), "%Y-%m-%d %I:%M:%S", gmtime(&tm));
- fprintf(ofd, "%s<%s>%s</%s>\n",indent,tag,tbuf,tag);
+ gbfprintf(ofd, "%s<%s>%s</%s>\n",indent,tag,tbuf,tag);
}
static void
hiketech_trkpt_pr(const waypoint *waypointp)
{
- fprintf(ofd, " <pnt>\n");
+ gbfprintf(ofd, " <pnt>\n");
if (waypointp->creation_time) {
hiketech_print_utc(waypointp->creation_time, " ", "utc");
}
- fprintf(ofd, " <lat>%f</lat>\n", waypointp->latitude);
- fprintf(ofd, " <long>%f</long>\n", waypointp->longitude);
+ gbfprintf(ofd, " <lat>%f</lat>\n", waypointp->latitude);
+ gbfprintf(ofd, " <long>%f</long>\n", waypointp->longitude);
if (waypointp->altitude != unknown_alt) {
- fprintf(ofd, " <alt>%f</alt>\n",
+ gbfprintf(ofd, " <alt>%f</alt>\n",
waypointp->altitude);
}
- fprintf(ofd, " </pnt>\n");
+ gbfprintf(ofd, " </pnt>\n");
}
static void
hiketech_waypt_pr(const waypoint *wpt)
{
- fprintf(ofd, "<wpt>\n");
+ gbfprintf(ofd, "<wpt>\n");
write_xml_entity(ofd, "\t", "ident", wpt->shortname);
write_optional_xml_entity(ofd, "\t", "sym", wpt->icon_descr);
- fprintf(ofd, "\t<lat>%f</lat>\n", wpt->latitude);
- fprintf(ofd, "\t<long>%f</long>\n", wpt->longitude);
+ gbfprintf(ofd, "\t<lat>%f</lat>\n", wpt->latitude);
+ gbfprintf(ofd, "\t<long>%f</long>\n", wpt->longitude);
/*
* These probably aren't technicallyconstants, but it's all
* we can do for now.
*/
- fprintf(ofd, "\t<color>\n\t\t<lbl>FAFFB4</lbl>\n\t\t<obj>FF8000</obj>\n\t</color>\n");
- fprintf(ofd, "</wpt>\n");
+ gbfprintf(ofd, "\t<color>\n\t\t<lbl>FAFFB4</lbl>\n\t\t<obj>FF8000</obj>\n\t</color>\n");
+ gbfprintf(ofd, "</wpt>\n");
}
static void
hiketech_write(void)
{
- fprintf(ofd, "<hiketech version=\"1.2\" url=\"http://www.hiketech.com\">\n");
- fprintf(ofd, "<gpsdata>\n");
+ gbfprintf(ofd, "<hiketech version=\"1.2\" url=\"http://www.hiketech.com\">\n");
+ gbfprintf(ofd, "<gpsdata>\n");
track_disp_all(hiketech_trk_hdr, hiketech_trk_tlr, hiketech_trkpt_pr);
track_disp_all(NULL, NULL, hiketech_trkpt_pr);
waypt_disp_all(hiketech_waypt_pr);
- fprintf(ofd, "</gpsdata>\n");
- fprintf(ofd, "</hiketech>\n");
+ gbfprintf(ofd, "</gpsdata>\n");
+ gbfprintf(ofd, "</hiketech>\n");
}
static
static void getAttr(const char *data, const char *attr, char **val, char seperator);
static FILE *fd;
-static FILE *ofd;
+static gbfile *ofd;
static
arglist_t hsa_ndv_args[] = {
static void
hsa_ndv_wr_init(const char *fname)
{
- ofd = xfopen(fname, "w", MYNAME);
+ ofd = gbfopen(fname, "w", MYNAME);
}
static void
hsa_ndv_wr_deinit(void)
{
- fclose(ofd);
+ gbfclose(ofd);
}
static int legNum = 0;
hsa_ndv_waypt_pr(const waypoint *waypointp)
{
- fprintf(ofd, "\t\t<Object>\n");
+ gbfprintf(ofd, "\t\t<Object>\n");
- fprintf(ofd, "\t\t\t<ClassName>waypnt</ClassName>\n");
+ gbfprintf(ofd, "\t\t\t<ClassName>waypnt</ClassName>\n");
//ignore these for now, they are s57 specific
// fprintf(ofd, "\t\t\t<FeatureNameAgency>0</FeatureNameAgency>\n");
// fprintf(ofd, "\t\t\t<FeatureNameSubDiv>1</FeatureNameSubDiv>\n");
// fprintf(ofd, "\t\t\t<FeatureNameNumber>1089009023</FeatureNameNumber>\n");
- fprintf(ofd, "\t\t\t<Attr><![CDATA[attr=grpnam%s\x1ftrnrad50\x1fOBJNAM%s\x1flegnum%i\x1fusrmrk%s\x1fselect2\1f]]></Attr>\n", routeName, waypointp->shortname, legNum, waypointp->description);
- fprintf(ofd, "\t\t\t<LegAttr><![CDATA[attr=grpnam%s\x1f]]></LegAttr>\n", routeName);
- fprintf(ofd, "\t\t\t<NumberOfVertexs>1</NumberOfVertexs>\n");
- fprintf(ofd, "\t\t\t<Latitude>%lf</Latitude>\n", waypointp->latitude);
- fprintf(ofd, "\t\t\t<Longitude>%lf</Longitude>\n", waypointp->longitude);
+ gbfprintf(ofd, "\t\t\t<Attr><![CDATA[attr=grpnam%s\x1ftrnrad50\x1fOBJNAM%s\x1flegnum%i\x1fusrmrk%s\x1fselect2\1f]]></Attr>\n", routeName, waypointp->shortname, legNum, waypointp->description);
+ gbfprintf(ofd, "\t\t\t<LegAttr><![CDATA[attr=grpnam%s\x1f]]></LegAttr>\n", routeName);
+ gbfprintf(ofd, "\t\t\t<NumberOfVertexs>1</NumberOfVertexs>\n");
+ gbfprintf(ofd, "\t\t\t<Latitude>%lf</Latitude>\n", waypointp->latitude);
+ gbfprintf(ofd, "\t\t\t<Longitude>%lf</Longitude>\n", waypointp->longitude);
- fprintf(ofd, "\t\t</Object>\n");
+ gbfprintf(ofd, "\t\t</Object>\n");
legNum++;
}
static void
hsa_ndv_write(void)
{
- fprintf(ofd, "<?xml version=\"1.0\"?>\n");
- fprintf(ofd, "<Export>\n");
- fprintf(ofd, "\t<Route>\n");
- fprintf(ofd, "\t\t<Version>1.0000000</Version>\n");
- fprintf(ofd, "\t\t<Name>ROUTENAME</Name>\n"); /*TODO: used filename? */
- fprintf(ofd, "\t\t<LastModified>0</LastModified>\n");
+ gbfprintf(ofd, "<?xml version=\"1.0\"?>\n");
+ gbfprintf(ofd, "<Export>\n");
+ gbfprintf(ofd, "\t<Route>\n");
+ gbfprintf(ofd, "\t\t<Version>1.0000000</Version>\n");
+ gbfprintf(ofd, "\t\t<Name>ROUTENAME</Name>\n"); /*TODO: used filename? */
+ gbfprintf(ofd, "\t\t<LastModified>0</LastModified>\n");
waypt_disp_all(hsa_ndv_waypt_pr);
- fprintf(ofd, "\t</Route>\n");
+ gbfprintf(ofd, "\t</Route>\n");
//later we'll import past tracks and chart objects?
// fprintf(ofd, "\t<Chartwork>\n");
// fprintf(ofd, "\t</Chartwork>\n");
- fprintf(ofd, "</Export>\n");
+ gbfprintf(ofd, "</Export>\n");
}
ff_vecs_t HsaEndeavourNavigator_vecs = {
/*
- Support for IGN Rando track files,
+ Support for IGN Rando track files.
- Copyright (C) 2005 Olaf Klein, o.b.klein@gpsbabel.org
+ Copyright (C) 2005,2006 Olaf Klein, o.b.klein@gpsbabel.org
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
#define MYNAME "IGNRando"
-static FILE *fout;
+static gbfile *fout;
static route_head *track;
static waypoint *wpt;
/* write support */
-static void
-ignr_fprintf(FILE *f, const char *fmt, ...)
-{
- char buff[256];
- char *temp = buff;
- va_list args;
- int i;
-
- va_start(args, fmt);
-
- i = vsnprintf(buff, sizeof(buff), fmt, args);
- if (i >= (int) sizeof(buff))
- {
- temp = xmalloc(i + 1);
- i = vsnprintf(temp, i + 1, fmt, args);
- }
- if (i < 0)
- {
- fatal(MYNAME ": error in vsnprintf.\n");
- }
- else if (i > 0)
- {
- char eol = temp[i - 1];
- if (eol == '\n') i--;
- fwrite(temp, 1, i, f);
- if (eol == '\n') fprintf(f, "\r\n");
- }
-
- if (temp != buff) xfree(temp);
- va_end(args);
-}
-
/* callbacks registered in ignr_vecs */
static void
ignr_rw_init(const char *fname)
{
- fout = xfopen(fname, "wb", MYNAME);
+ fout = gbfopen(fname, "w", MYNAME);
}
static void
ignr_rw_deinit(void)
{
- fclose(fout);
+ gbfclose(fout);
}
static void
if (track_num != track_index) return;
- ignr_fprintf(fout, "\t<INFORMATIONS>\n");
- ignr_fprintf(fout, "\t\t<NB_ETAPES>%d</NB_ETAPES>\n", track->rte_waypt_ct);
+ gbfprintf(fout, "\t<INFORMATIONS>\n");
+ gbfprintf(fout, "\t\t<NB_ETAPES>%d</NB_ETAPES>\n", track->rte_waypt_ct);
if (track->rte_desc != NULL)
- ignr_fprintf(fout, "\t\t<DESCRIPTION>%s</DESCRIPTION>\n", track->rte_desc);
- ignr_fprintf(fout, "\t</INFORMATIONS>\n");
+ gbfprintf(fout, "\t\t<DESCRIPTION>%s</DESCRIPTION>\n", track->rte_desc);
+ gbfprintf(fout, "\t</INFORMATIONS>\n");
}
static void
{
if (track_num != track_index) return;
- ignr_fprintf(fout, "\t<ETAPE>\n");
- ignr_fprintf(fout, "\t\t<POSITION>%3.6f,%3.6f</POSITION>\n", wpt->latitude, wpt->longitude);
+ gbfprintf(fout, "\t<ETAPE>\n");
+ gbfprintf(fout, "\t\t<POSITION>%3.6f,%3.6f</POSITION>\n", wpt->latitude, wpt->longitude);
if (wpt->altitude != unknown_alt)
- ignr_fprintf(fout, "\t\t<ALTITUDE>%3.6f</ALTITUDE>\n", wpt->altitude);
- ignr_fprintf(fout, "\t</ETAPE>\n");
+ gbfprintf(fout, "\t\t<ALTITUDE>%3.6f</ALTITUDE>\n", wpt->altitude);
+ gbfprintf(fout, "\t</ETAPE>\n");
}
static void
now = current_time();
tm = *localtime(&now);
- ignr_fprintf(fout, "<?xml version=\"1.0\" encoding=\"windows-1252\"?>\n");
- ignr_fprintf(fout, "<RANDONNEE>\n");
- ignr_fprintf(fout, "\t<ENTETE>\n");
- ignr_fprintf(fout, "\t\t<VERSION_XML>1.1</VERSION_XML>\n");
- ignr_fprintf(fout, "\t\t<VERSION_BASE>IHA03AA</VERSION_BASE>\n");
+ gbfprintf(fout, "<?xml version=\"1.0\" encoding=\"windows-1252\"?>\n");
+ gbfprintf(fout, "<RANDONNEE>\n");
+ gbfprintf(fout, "\t<ENTETE>\n");
+ gbfprintf(fout, "\t\t<VERSION_XML>1.1</VERSION_XML>\n");
+ gbfprintf(fout, "\t\t<VERSION_BASE>IHA03AA</VERSION_BASE>\n");
strftime(buff, sizeof(buff), "%d/%m/%Y", &tm);
- ignr_fprintf(fout, "\t\t<DATE>%s</DATE>\n", buff);
+ gbfprintf(fout, "\t\t<DATE>%s</DATE>\n", buff);
strftime(buff, sizeof(buff), "%H:%M:%S", &tm);
- ignr_fprintf(fout, "\t\t<HEURE>%s</HEURE>\n", buff);
+ gbfprintf(fout, "\t\t<HEURE>%s</HEURE>\n", buff);
- ignr_fprintf(fout, "\t</ENTETE>\n");
+ gbfprintf(fout, "\t</ENTETE>\n");
track_disp_all(ignr_write_track_hdr, ignr_write_track_trl, ignr_write_waypt);
- ignr_fprintf(fout, "</RANDONNEE>\n");
+ gbfprintf(fout, "</RANDONNEE>\n");
}
ff_vecs_t ignr_vecs = {
#define MYNAME "XML Reader"
void
-write_xml_header(FILE *ofd)
+write_xml_header(gbfile *ofd)
{
char buff[128];
cet_cs_vec_t *cs = cet_find_cs_by_name(CET_CHARSET_ASCII);
snprintf(buff, sizeof(buff), " encoding=\"%s\"", global_opts.charset_name);
else
buff[0] = 0;
- fprintf(ofd, "<?xml version=\"1.0\"%s?>\n", buff);
+ gbfprintf(ofd, "<?xml version=\"1.0\"%s?>\n", buff);
}
void
-write_xml_entity(FILE *ofd, const char *indent,
+write_xml_entity(gbfile *ofd, const char *indent,
const char *tag, const char *value)
{
char *tmp_ent = xml_entitize(value);
- fprintf(ofd, "%s<%s>%s</%s>\n", indent, tag, tmp_ent, tag);
+ gbfprintf(ofd, "%s<%s>%s</%s>\n", indent, tag, tmp_ent, tag);
xfree(tmp_ent);
}
void
-write_optional_xml_entity(FILE *ofd, const char *indent,
+write_optional_xml_entity(gbfile *ofd, const char *indent,
const char *tag, const char *value)
{
if (value && *value)
}
void
-write_xml_entity_begin0(FILE *ofd, const char *indent,
+write_xml_entity_begin0(gbfile *ofd, const char *indent,
const char *tag)
{
- fprintf(ofd, "%s<%s>\n", indent, tag);
+ gbfprintf(ofd, "%s<%s>\n", indent, tag);
}
void
-write_xml_entity_begin1(FILE *ofd, const char *indent,
+write_xml_entity_begin1(gbfile *ofd, const char *indent,
const char *tag, const char *attr,
const char *attrval)
{
- fprintf(ofd, "%s<%s %s=\"%s\">\n", indent, tag, attr, attrval);
+ gbfprintf(ofd, "%s<%s %s=\"%s\">\n", indent, tag, attr, attrval);
}
void
-write_xml_entity_begin2(FILE *ofd, const char *indent,
+write_xml_entity_begin2(gbfile *ofd, const char *indent,
const char *tag, const char *attr1,
const char *attrval1, const char *attr2,
const char *attrval2)
{
- fprintf(ofd, "%s<%s %s=\"%s\" %s=\"%s\">\n", indent, tag, attr1, attrval1, attr2, attrval2);
+ gbfprintf(ofd, "%s<%s %s=\"%s\" %s=\"%s\">\n", indent, tag, attr1, attrval1, attr2, attrval2);
}
void
-write_xml_entity_end(FILE *ofd, const char *indent,
+write_xml_entity_end(gbfile *ofd, const char *indent,
const char *tag)
{
- fprintf(ofd, "%s</%s>\n", indent, tag);
+ gbfprintf(ofd, "%s</%s>\n", indent, tag);
}
void
}
void
-xml_write_time(FILE *ofd, const time_t timep, char *elname)
+xml_write_time(gbfile *ofd, const time_t timep, char *elname)
{
char time_string[64];
xml_fill_in_time(time_string, timep, XML_LONG_TIME);
if (time_string[0]) {
- fprintf(ofd, "<%s>%s</%s>\n",
+ gbfprintf(ofd, "<%s>%s</%s>\n",
elname,
time_string,
elname
} xg_tag_mapping;
-void write_xml_entity(FILE *ofd, const char *indent,
+void write_xml_entity(gbfile *ofd, const char *indent,
const char *tag, const char *value);
-void write_xml_entity_begin0(FILE *ofd, const char *indent,
+void write_xml_entity_begin0(gbfile *ofd, const char *indent,
const char *tag);
-void write_xml_entity_begin1(FILE *ofd, const char *indent, const char *tag,
+void write_xml_entity_begin1(gbfile *ofd, const char *indent, const char *tag,
const char *attr1, const char *attrval1);
-void write_xml_entity_begin2(FILE *ofd, const char *indent, const char *tag,
+void write_xml_entity_begin2(gbfile *ofd, const char *indent, const char *tag,
const char *attr1, const char *attrval1,
const char *attr2, const char *attrval2);
-void write_xml_entity_end(FILE *ofd, const char *indent, const char *tag);
+void write_xml_entity_end(gbfile *ofd, const char *indent, const char *tag);
-void write_optional_xml_entity(FILE *ofd, const char *indent,
+void write_optional_xml_entity(gbfile *ofd, const char *indent,
const char *tag, const char *value);
-void xml_write_time(FILE *ofd, const time_t timep, char *elname);
+void xml_write_time(gbfile *ofd, const time_t timep, char *elname);
void xml_fill_in_time(char *time_string, const time_t timep,
int long_or_short);
-void write_xml_header(FILE *ofd);
+void write_xml_header(gbfile *ofd);
void xml_ignore_tags(const char **taglist);
void xml_init(const char *fname, xg_tag_mapping *tbl,const char *encoding);